package atguigu;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

public class WeixinUtil {

	public static void main(String[] args) {
//    	 long milliSecond = 1602741600000L;
//         Date date = new Date();
//         date.setTime(milliSecond);
//         System.out.println(new SimpleDateFormat().format(date));

//         List<Integer> list = Arrays.asList(5,8,23,78);
//         
//         Collections.sort(list);
//         
//         System.out.println(list);

//    	
//    	Integer a[] = new Integer[] {1,2,3,4,5};
//    	
//    	int x = a.length % 2;
//    	int y = a.length / 2;
//    	System.out.println(x);
//    	System.out.println(y);
//    	
//    	int z = 1 / 2;
//    	System.out.println(z);

//    	String stragegy = "QYC:G5";
//    	if(stragegy.indexOf(":") == -1 && stragegy.indexOf("：") == -1) {
//    		System.out.println("格式错误");
//    	}else {
//    		System.out.println("格式正确");
//    	}
//         
//    	String nameString = "李5867(lilian1)";
//    	
//    	int index1 = nameString.indexOf("(");
//    	int index2 = nameString.indexOf(")");
//    	
//    	System.out.println(index1);
//    	System.out.println(index2);
//    	
//    	String substring = nameString.substring(5+1, 13);
//    	System.out.println(substring);
//    	
//    	WeixinUtil wu = new WeixinUtil();
//    	// 505:D1;815:G2
//    	int[] cellIndex = wu.getCellIndex("505","505:D1；815：G2");
//    	System.out.println(cellIndex[0]);
//    	System.out.println(cellIndex[1]);

//    	int[] cellIndex2 = wu.getCellIndex("A11"); // 列行

//    	System.out.println(cellIndex2[0]); // 
//    	System.out.println(cellIndex2[1]);

//    	String str = "美的_美的集团_机电事业群_品质_可靠性工程中心_空压测试中心_制品小组";
//    	int lastIndexOf = str.lastIndexOf("_");
//    	System.out.println(lastIndexOf);
//    	String s = str.substring(lastIndexOf+1, str.length());
//    	System.out.println(s);

//    	str.substring(beginIndex, endIndex)

//    	String string = "102230304K";
//    	String substring = string.substring(0,string.length()-1);
//    	System.out.println(substring);
//    	
//    	
//    	String substring2 = substring.substring(substring.length()-2, substring.length());
//    	System.out.println(substring2);
//		String str = "aa,bb;cc,dd;xx yy";
//		String[] v = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, "");
//		System.out.println(Arrays.toString(v));

		String str = "chenjb9";
		String consigner = getConsigner(str);
		System.out.println(consigner);


	}

	public static String getConsigner(String consigner) {
		String consi = null;
		if(org.apache.commons.lang.StringUtils.isNotBlank(consigner)){
			if(consigner.indexOf("(") != -1 && consigner.indexOf(")")!=-1){
				int start = consigner.indexOf("(");
				int end = consigner.indexOf(")");
				consi = consigner.substring(start+1, end);
			}else{
				consi = consigner;
			}
		}
		return consi;
	}

	private int[] getCellIndex(String location) {

		String hang = null;
		String lie = null;

		Pattern expression = Pattern.compile("[a-zA-Z]+");// 创建匹配模式
		Matcher matcher = expression.matcher(location);// 通过匹配模式得到匹配器
		if (matcher.find()) {
			lie = matcher.group();
		}

		expression = Pattern.compile("[0-9]+");// 创建匹配模式
		matcher = expression.matcher(location);// 通过匹配模式得到匹配器
		if (matcher.find()) {
			hang = matcher.group();
		}

		int index[] = { 0, 0 };

		// 行索引
		if (StringUtils.isNotBlank(hang)) {
			int row = Integer.parseInt(hang) - 1;
			index[0] = row;
		}

		// 列的索引
		if (StringUtils.isNotBlank(lie)) {
			int cell = excelColStrToNum(lie, lie.length()) - 1;
			if (index == null) {
				index[0] = 0;
				index[1] = cell;
			} else {
				if (index.length > 0) {
					index[1] = cell;
				} else {
					index[0] = 0;
					index[1] = cell;
				}
			}
		}
		return index;
	}

	/**
	 * 根据用户看到的excel中的位置，获取代码中实际用到的索引位置
	 * 
	 * @param name     excel解析器的名字
	 * @param stragegy 用户描述的excel格子的位置信息
	 * @return
	 */
	public int[] getCellIndex(String name, String stragegy) {
		// 定义这个属性和excel中的对应关系
		// 505:D1;815:G2
		stragegy = stragegy.replaceAll("：", ":");
		System.out.println(stragegy);
		stragegy = stragegy.replaceAll("；", ";");
		System.out.println(stragegy);

		if (StringUtils.isBlank(name) || StringUtils.isBlank(stragegy))
			return null;
		if (stragegy.indexOf(":") == -1 && stragegy.indexOf("：") == -1)
			return null;
		String[] split = stragegy.split(";");
		String wz = "";
		for (String s : split) {
			s = s.replaceAll(" ", ""); // 去掉空格
			String[] split1 = {};
			if (s.indexOf(":") != -1) {
				split1 = s.split(":");
			} else if (s.indexOf("：") != -1) {
				split1 = s.split("：");
			}
			if (split1[0].equals(name)) {
				wz = split1[1];
			}
		}

		String hang = null;
		String lie = null;

		Pattern expression = Pattern.compile("[a-zA-Z]+");// 创建匹配模式
		Matcher matcher = expression.matcher(wz);// 通过匹配模式得到匹配器
		if (matcher.find()) {
			lie = matcher.group();
		}

		expression = Pattern.compile("[0-9]+");// 创建匹配模式
		matcher = expression.matcher(wz);// 通过匹配模式得到匹配器
		if (matcher.find()) {
			hang = matcher.group();
		}

		int index[] = { 0, 0 };

		if (StringUtils.isNotBlank(hang)) {
			int row = Integer.parseInt(hang) - 1;
			index[0] = row;
		}

		if (StringUtils.isNotBlank(lie)) {
			int cell = excelColStrToNum(lie, lie.length()) - 1;
			if (index == null) {
				index[0] = 0;
				index[1] = cell;
			} else {
				if (index.length > 0) {
					index[1] = cell;
				} else {
					index[0] = 0;
					index[1] = cell;
				}
			}
		}

		return index;
	}

	public int excelColStrToNum(String colStr, int length) {
		int num = 0;
		int result = 0;
		for (int i = 0; i < length; i++) {
			char ch = colStr.charAt(length - i - 1);
			num = (int) (ch - 'A' + 1);
			num *= Math.pow(26, i);
			result += num;
		}
		return result;
	}

}